<template>
    <view class="content">
        <u-form :model="examineForm" class="loginForm" ref="personalRef" :rules="rules" label-width="80">
            <u-form-item label="用户角色：" prop="roleIds" borderBottom>
                <view class="divCenterH" style="flex-wrap: wrap">
                    <u-tag v-for="(item, index) in examineForm.roleNames" :key="index" type="info" class="marr-10 marb-10" :text="item" />
                </view>
            </u-form-item>
            <u-form-item label="登录名：" prop="loginName" borderBottom>
                <view>{{ examineForm.loginName }}</view>
            </u-form-item>
            <u-form-item label="姓名：" prop="name" borderBottom>
                <u-input v-model="examineForm.name" placeholder="请输入姓名" type="text" border="none" />
            </u-form-item>
            <u-form-item label="手机号：" prop="phone" borderBottom>
                <u-input v-model="examineForm.phone" placeholder="请输入手机号" type="text" border="none" />
            </u-form-item>
            <u-form-item label="邮箱：" prop="email" borderBottom>
                <u-input v-model="examineForm.email" placeholder="请输入邮箱" type="text" border="none" />
            </u-form-item>
        </u-form>
        <view class="mart-80">
            <u-button @click="commitMath()" type="primary" size="default">提交</u-button>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            examineForm: {
                roleNameList: [],

                loginName: "",
                name: "",
                phone: "",
                email: "",
            },
            rules: {
                name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
                phone: [
                    { required: true, message: "请输入手机号", trigger: "blur" },
                    {
                        validator: (rule, value, callback) => {
                            return this.$u.test.mobile(value);
                        },
                        message: "手机号码不正确",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
    onReady() {
        this.openEdit();
    },
    methods: {
        openEdit() {
            this.$app.CallApi(this.$app.api.User.GetByID(getApp().globalData.userID), {
                success: (res) => {
                    this.examineForm = res;
                },
            });
        },
        commitMath() {
            let that = this;
            this.$refs.personalRef.validate().then(() => {
                this.$app.CallApi(this.$app.api.User.Update, {
                    data: this.examineForm,
                    success: (res) => {
                        that.$u.toast("修改成功");
                        that.$app.UpdateMe({
                            success: (res) => {
                                getApp().globalData = res;
                                uni.setStorageSync(that.$config.MeKey, res);
                            },
                        });
                        setTimeout(() => {
                            uni.navigateBack();
                        }, 500);
                    },
                });
            });
        },
    },
};
</script>

<style scoped></style>
